package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 获取文章列表
     * @param wmNewsPageReqDto
     * @return
     */
    @PostMapping("list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto wmNewsPageReqDto){
        return wmNewsService.findAll(wmNewsPageReqDto);
    }

    /**
     * 发布文章
     * @param wmNewsDto
     * @return
     */
    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.submitNews(wmNewsDto);
    }

    /**
     * 文章上下架
     * @param wmNewsDto
     * @return
     */
    @PostMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.downOrUp(wmNewsDto);
    }


    /**
     * 审核文章 获取文章列表
     * @param newsAuthDto
     * @return
     */
    @PostMapping("list_vo")
    public ResponseResult list(@RequestBody NewsAuthDto newsAuthDto){
        return wmNewsService.getList(newsAuthDto);
    }

    /**
     * 查询文章详情
     * @param id
     * @return
     */
    @GetMapping("one_vo/{id}")
    public ResponseResult getById(@PathVariable Integer id){
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    /**
     *  审核失败
     * @param newsAuthDto
     * @return
     */
    @PostMapping("auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto newsAuthDto){
        return wmNewsService.authFail(newsAuthDto);
    }

    /**
     *  审核成功
     * @param newsAuthDto
     * @return
     */
    @PostMapping("auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto newsAuthDto){
        return wmNewsService.authPass(newsAuthDto);
    }

}
